// RelativeLayoutTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "IntrusivePointer.h"
#include "FakeNode.h"
#include "ClientParams.h"
#include "LayoutFactory.h"
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
	using namespace fusion;
	using namespace fusion::mode10;
	// test 1, create tree
	Ref<Node> root = new Node(1,1);
	root->sizeX = 25; root->sizeY = 20;
	Ref<Node> childA = new Node(2,2);
	childA->sizeX = 10; childA->sizeY = 10;
	Ref<Node> childB = new Node(3,3);
	childB->sizeX= 20; childB->sizeY = 20;
	Ref<Node> childC = new Node(4,4);
	childC->sizeX= 15; childC->sizeY = 15;
	root->AddChild(childA);
	root->AddChild(childB);
	childB->AddChild(childC);
	
	// add params on node
	Ref<ClientParamsAdapter> paramsA = new ClientParamsAdapter(10,10);
	paramsA->SetParam(RelativeLayout::RelativeLayoutParams::, 1);
	Ref<ClientParamsAdapter> paramsB = new ClientParamsAdapter(BaseLayoutParams::WRAP_CONTENT,
		BaseLayoutParams::WRAP_CONTENT);
	paramsB->SetParam(RelativeLayout::RelativeLayoutParams::AlignLeft, 2);
	paramsB->SetParam(RelativeLayout::RelativeLayoutParams::Below, 2);
	Ref<ClientParamsAdapter> paramsC = new ClientParamsAdapter(BaseLayoutParams::WRAP_CONTENT,
		BaseLayoutParams::WRAP_CONTENT);
	paramsC->SetParam(RelativeLayout::RelativeLayoutParams::AlignTop, 3);
	paramsC->SetParam(RelativeLayout::RelativeLayoutParams::RightOf, 3);

	// simulate create layout on node tree
	LayoutFactory::AddLayoutEffect(childA, paramsA);
	LayoutFactory::AddLayoutEffect(childB, paramsB);
	LayoutFactory::AddLayoutEffect(childC, paramsC);

	// simulate running layout
	Ref<LayoutNode> rootLayout = root->GetRelatedLayout();
	if (rootLayout)
	{
		if (rootLayout->IsLayoutable())
		{
			Ref<MeasureSpec> widthSpec = MeasureSpec::GenerateMeasureSpec(root->sizeX, MeasureSpec::EXACTLY);
			Ref<MeasureSpec> heightSpec = MeasureSpec::GenerateMeasureSpec(root->sizeY, MeasureSpec::EXACTLY);
			rootLayout->Measure(widthSpec, heightSpec);
		}
	}
	/*Ref<LayoutBase> layout = root->GetLayout();
	Ref<RelativeLayout> rLayout = static_cast<RelativeLayout*>(layout.get());
	if (rLayout)
	{
		rLayout->RequestLayout();
		Ref<MeasureSpec> widthSpec = MeasureSpec::GenerateMeasureSpec(root->sizeX, MeasureSpec::EXACTLY);
		Ref<MeasureSpec> heightSpec = MeasureSpec::GenerateMeasureSpec(root->sizeY, MeasureSpec::EXACTLY);
		rLayout->Measure(widthSpec, heightSpec);
	}*/

	std::cout << "press enter to continue..." <<std::endl;
	unsigned short waitEnd;
	std::cin>>waitEnd;
	return 0;
}

